classdef Turb < Processor
  % Class for calculating turbidity ala SBE Data Procesing
  % Derived from Processor
  % Constructor signature: NTU = Turb(data, conn), both args optional
  %
  % Author: David Goldsmith, Wash. State Dept. of Ecology, dgol461@ecy.wa.gov
  % Release date: N/A
  
    properties
      % inherited from Processor
%         inData;
%         castDT;
%         scanRate;
%         ParamID;
%         ParamDesc;
%         SBEprec;
%         EquipID;
        DBdata;
        outData;
    end
    
    methods
        function NTU = Turb(data, conn) % Constructor
            if nargin < 1, data = []; end
            if nargin < 2, conn = []; end
            NTU = NTU@Processor(data);
            if ~isempty(conn), NTU.getDBdata(conn, 'U'); end
            if ~isempty(data) && ~isempty(conn), NTU.mainFormula(); end
        end
        
        function delete(obj) % Destructor
            % Here in case I need it
        end
        
        function mainFormula(obj)
            A0  = obj.inData.Sensors.UserPolynomialSensor.A0;
            A1  = obj.inData.Sensors.UserPolynomialSensor.A1;
            A2  = obj.inData.Sensors.UserPolynomialSensor.A2;
            A3  = obj.inData.Sensors.UserPolynomialSensor.A3;
            V   = obj.inData.rV(:,obj.inData.Sensors.UserPolynomialSensor.index-2); 
            NTU = A0 + A1*V;
            if A2
                NTU = NTU + A2*V.*V;
            end
            if A3
                NTU = NTU + A3*V.*V.*V;
            end
            obj.outData = NTU;
        end
        
    end
    
end